﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using COMPONENT.Entity;
using COMPONENT.Library.Conexion;

namespace COMPONENT.Dao
{
    public class clsTarjetaDAO
    {
        private clsTarjetaDAO()
        {

        }
        private static clsTarjetaDAO instancia = null;
        public static clsTarjetaDAO Instancia
        {
            get
            {
                if (instancia == null)
                {
                    instancia = new clsTarjetaDAO();
                }
                return instancia;
            }
        }
        public clsTarjeta ListarTarjetaxId(Int32 ID)
        {
            clsTarjeta obj = null;
            SqlDataReader dr = null;
            SqlCommand cmd = null;
            try
            {
                cmd = new SqlCommand("SP_LISTARXID_TARJETA", clsConexion.GetConexion());
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@ID", ID);
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    obj = new clsTarjeta();
                    obj.ID = Convert.ToInt32(dr["IdTarjeta"]);
                    obj.NumTarjeta = dr["NumeroTarjeta"].ToString();
                    obj.TipoTarjeta = dr["Tipo"].ToString();
                    obj.CodigoSeguridad = Convert.ToInt32(dr["CodigoSeguridad"]);
                    obj.AñoExp = Convert.ToInt32(dr["AñoExpiracion"].ToString());
                    obj.MesExp = Convert.ToInt32(dr["MesExpiracion"].ToString());
                    obj.NombreCuenta = dr["NombreCuenta"].ToString();

                }
            }
            catch (Exception ex)
            {
                obj = null;
            }
            finally
            {
                cmd.Connection.Close();
                dr.Close();
            }
            return obj;
        }
    }
}
